from . import users
from .controllers import User
from flask import jsonify


@users.route('/users')
def listUsers():
    user = User()
    users = user.listAll()
    result = []
    for employee in users:
        result.append(employee.to_json())
    return jsonify(result), 200

@users.route('/users/create', methods=['POST'])
def createUsers():
    user = User()
    result = user.create()
    return jsonify(result['desc']), result['code']

@users.route('/users/<empId>', methods=['PUT'])
def updateUsers(empId):
    user = User()
    result = user.update(empId)
    return jsonify({'desc': result['desc']}), result['code']

@users.route('/users/<empId>', methods=['DELETE'])
def deleteUsers(empId):
    user = User()
    result = user.delete(empId)
    return jsonify({'desc': result['desc']}), result['code']

@users.route('/users/login', methods=['POST'])
def loginUsers():
    user = User()
    result = user.login()
    return jsonify(result['desc']), result['code']